//
//  Record+CoreDataClass.m
//  RecordApp
//
//  Created by chaichai on 2022/3/2.
//
//

#import "Record+CoreDataClass.h"
#import "DataBaseManager.h"
#import "NSDate+helper.h"
@implementation Record
+(instancetype)create:(NSDate *)date
{
    Record *obj =
    [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass(self.class) inManagedObjectContext:[DataBaseManager sharedManager].contex];
    obj.date = date;
    obj.day = date.day;
    return obj;
}
+(NSArray *)queryRecord:(NSDate *)date
{
    NSFetchRequest *request = [self fetchRequest];
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"day == %ld",date.day];
    NSError *error = nil;
    [request setPredicate:pred];
    NSArray *resArr =
    [[DataBaseManager sharedManager].contex executeFetchRequest:request
                                                          error:&error];
    return resArr;
}
+(NSArray *)queryRecordBegin:(NSInteger)start withEnd:(NSInteger)end
{
    NSFetchRequest *request = [self fetchRequest];
    NSPredicate *pred =
    [NSPredicate predicateWithFormat:@"day >= %ld AND day <= %ld",start,end];
    NSError *error = nil;
    [request setPredicate:pred];
    NSArray *resArr =
    [[DataBaseManager sharedManager].contex executeFetchRequest:request
                                                          error:&error];
    return resArr;
}
@end
